<?php
global $ij;
$ij->registerController('ControllerCore');
/**
 * Description of cUrlParser
 *
 * @author Faceless
 */
class cUrlParser extends cControllerCore{
    protected $modelSections;
    protected $urlDelimeter = '/';

    public function __construct() {
        $ij->registerModel('Sections');
        $this->modelSections = new mSections();
    }

    protected static function normalizeUrl($url) {
        //TODO: make code =)
        return $url;
    }

    public function parseUrl($url){
        self::normalizeUrl($url);
        $urlParts = explode($this->urlDelimeter, $url);

        $controller = null;
        $params = null;

        foreach ($urlParts as $key => $cUrlPart) {
            $cSection = $this->modelSections->getSection($cUrlPart);
            if ($cSection) {
                $controller = $cSection['controller'];
            }
            else {
                $params = array_slice($urlParts, $key);
                break;
            }
        }

        return array(
            'controller' => $controller,
            'params' => $params
        );
    }
}
?>
